package com.ehome.poct.base.dao.device.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ehome.core.util.BeanConvertUtil;
import com.ehome.mybatisplus.support.AbstractCrudRepository;
import com.ehome.poct.base.api.dto.device.DeviceBindDTO;
import com.ehome.poct.base.dao.device.entity.DeviceBindDO;
import com.ehome.poct.base.dao.device.mapper.DeviceBindMapper;
import com.ehome.poct.base.device.repository.DeviceBindRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * 设备绑定表RepositoryImpl
 *
 * @author wuyingchao
 * @Date 2022-07-14 14:15
 */
@Repository
@AllArgsConstructor
public class DeviceBindRepositoryImpl extends AbstractCrudRepository<DeviceBindDO, DeviceBindDTO> implements DeviceBindRepository {
    private final DeviceBindMapper mapper;

    @Override
    public DeviceBindDTO getLast(String sno) {
        final var entity = mapper.selectOne(Wrappers.<DeviceBindDO>lambdaQuery()
                .eq(DeviceBindDO::getSno, sno)
                .orderByDesc(DeviceBindDO::getCreateTime).last("limit 1"));
        return BeanConvertUtil.convertBean(entity, DeviceBindDTO.class);
    }
}
